package u1project.client;

import u1project.common.Request;
import u1project.common.Response;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Properties;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class MyClient_old {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        try {
            Properties prop=new Properties();
            prop.load(MyClient_old.class.getClassLoader().getResourceAsStream("u1project/client/ip.properties"));
            String ip=prop.getProperty("ServerIp","localhost");
            int port=Integer.parseInt(prop.getProperty("port","9999"));
            System.out.println(ip+","+port);
            //Socket s=new Socket("192.168.1.135",9996);
            Socket s=new Socket(ip,port);
            ObjectOutputStream oout=new ObjectOutputStream(s.getOutputStream());
            ObjectInputStream oin=new ObjectInputStream(s.getInputStream());
            while (true){
                System.out.println("1:登录，2：注册 3：上传 9：退出");
                int choice=in.nextInt();
                if(choice==1){
                    System.out.println("请输入用户名:");
                    String n=in.next();
                    System.out.println("请输入用户密码:");
                    String p=in.next();
                    Request request=new Request("login");
                    request.put("name",n);
                    request.put("password",p);
                    oout.writeObject(request);
                    oout.reset();
                    Response resp=(Response)oin.readObject();
                    if(resp.isSucess()){
                        System.out.println("成功了");
                    }else{
                        System.out.println("失败了，原因是"+resp.getMsg());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
